﻿<Controls:MetroWindow x:Class="RazorSourceGeneratorMain.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:avalonDock="http://avalondock.codeplex.com"
        xmlns:local="clr-namespace:RazorSourceGenerator.ViewModel"
        xmlns:conv="clr-namespace:RazorSourceGenerator.Converter"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
        xmlns:gmc="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
        DataContext="{Binding Main, Source={StaticResource Locator}}"
        Title="{Binding ConfigViewModel.Title}" Height="600" Width="800"
        WindowStartupLocation="CenterScreen" 
        Icon="/RazorSourceGeneratorMain;component/Images/RazorSourceGeneratorIcon.ico" >
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="KeyDown">
      <gmc:EventToCommand PassEventArgsToCommand="True" Command="{Binding KeyDownCommand}" />
    </i:EventTrigger>
    <i:EventTrigger EventName="Closing">
      <gmc:EventToCommand PassEventArgsToCommand="True" Command="{Binding ClosingCommand}" />
    </i:EventTrigger>
  </i:Interaction.Triggers>
  <!--Loaded="OnLoaded" Background="Transparent"-->
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="CommonStyle.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Window.Resources>
  <Controls:MetroWindow.WindowCommands>
    <Controls:WindowCommands>
      <Button Content="About" Command="{Binding AboutCommand}"/>
    </Controls:WindowCommands>
  </Controls:MetroWindow.WindowCommands>
  <Grid Name="gridMain">
    <Grid.Resources>
      <conv:VisibilityConverter x:Key="visibleConverter" />
      <conv:BindingNotNullConverter x:Key="bindingNotNullConverter" />
      <conv:TemplatesVisibleConverter x:Key="templatesVisibleConverter" />
      <conv:MultiEnabledConverter x:Key="multiEnabledConverter" />
      <Style x:Key="comboBoxStyle" TargetType="ComboBox">
        <Setter Property="Width" Value="200" />
        <Setter Property="Height" Value="22" />
      </Style>
      <Style TargetType="TextBox" x:Key="baseTextboxStyle">
        <Setter Property="Height" Value="22" />
        <Setter Property="Validation.ErrorTemplate">
          <Setter.Value>
            <ControlTemplate>
              <StackPanel Orientation="Horizontal">
                <TextBlock Foreground="Red" VerticalAlignment="Center" FontSize="18">!</TextBlock>
                <AdornedElementPlaceholder/>
              </StackPanel>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Style.Triggers>
          <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" />
          </Trigger>
        </Style.Triggers>
      </Style>
      <Style x:Key="headerLabelStyle" TargetType="Label">
        <Setter Property="HorizontalAlignment" Value="Left"></Setter>
        <Setter Property="Height" Value="28"></Setter>
        <Setter Property="VerticalAlignment" Value="Top"></Setter>
        <Setter Property="Width" Value="115"></Setter>
      </Style>
      <Style x:Key="listViewStyle" TargetType="ListView">
        <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
        <Setter Property="VerticalAlignment" Value="Stretch"></Setter>
        <Setter Property="SelectionMode" Value="Single"></Setter>
        <Setter Property="Focusable" Value="True"></Setter>
        <Setter Property="ItemContainerStyle">
          <Setter.Value>
            <Style TargetType="ListViewItem">
              <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFEDFAFF"/>
                <!--<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0.5,2" StartPoint="0.5,0">
                                    <GradientStop Color="#FFEDFAFF" Offset="0" />
                                    <GradientStop Color="#FFA7CDF0" Offset="1" />
                                </LinearGradientBrush>-->
              </Style.Resources>
              <Setter Property="HorizontalContentAlignment" Value="Stretch" />
              <Setter Property="BorderBrush" Value="LightGray"/>
              <Setter Property="BorderThickness" Value="0,0,0,1"/>
              <Setter Property="Padding" Value="0"/>
              <Setter Property="Margin" Value="0"/>
            </Style>
          </Setter.Value>
        </Setter>
      </Style>
      <Style x:Key="linkButtonStyle" TargetType="Button">
        <Setter Property="Width" Value="115" />
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="Button">
              <TextBlock TextDecorations="Underline" Margin="5" >  
                 <ContentPresenter />
              </TextBlock>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="Width" Value="Auto" />
        <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="Red"></Setter>
          </Trigger>
        </Style.Triggers>
      </Style>
      <DataTemplate x:Key="recentFile">
        <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.OpenCommand}" 
                  CommandParameter="{Binding FullPath}" ToolTip="{Binding FullPath}" >
          <MenuItem.Style>
            <Style TargetType="MenuItem">
              <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True" >
                  <Setter Property="Foreground" Value="White" />
                </Trigger>
              </Style.Triggers>
            </Style>
          </MenuItem.Style>
          <MenuItem.Template>
            <ControlTemplate>
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="20" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Index}" Margin="5 0 0 5" HorizontalAlignment="Right" VerticalAlignment="Center"  />
                <TextBlock Grid.Column="1" Text="{Binding FileName}" Margin="5 0 0 5" HorizontalAlignment="Left" VerticalAlignment="Center" />
              </Grid>
            </ControlTemplate>
          </MenuItem.Template>
        </MenuItem>
      </DataTemplate>
    </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Menu Name="menu" Grid.Row="0" Grid.Column="0" Background="Transparent">
      <MenuItem Header="NEW" Command="{Binding NewCommand}" />
      <MenuItem Header="OPEN" >
        <MenuItem Header="OPEN CONFIG" Command="{Binding OpenCommand}"/>
        <Separator />
        <MenuItem Header="OPEN SAMPLE(JAVA for iBatis)" Command="{Binding OpenCommand}" CommandParameter="sample"/>
      </MenuItem>
      <MenuItem Header="RECENT" ItemsSource="{Binding RecentFiles}" ItemTemplate="{StaticResource recentFile}" ></MenuItem>
      <MenuItem Header="SAVE"   Command="{Binding SaveCommand}"/>
      <MenuItem Header="SAVEAS" Command="{Binding SaveAsCommand}"/>
      <MenuItem Header="EXIT" Command="{Binding ExitCommand}"/>
    </Menu>
    <StackPanel Margin="5" Orientation="Horizontal" Grid.Row="1" Grid.Column="0">
      <Button Height="22" Width="100" Content="EXECUTE(F5)" Command="{Binding ExecuteCommand}" Background="#FFA7CDF0" />
      <Button Margin="5 0 0 0" Height="22" Width="100" Content="CANCEL" Command="{Binding CancelCommand}" IsEnabled="{Binding ConfigViewModel.IsRunning}"/>
      <Controls:ProgressIndicator Margin="20 0 0 0"
                   Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ConfigViewModel.IsRunning, Converter={StaticResource visibleConverter}}" 
                                        ProgressColour="{StaticResource AccentColorBrush}" Height="4" Width="400" />
    </StackPanel>
    <avalonDock:DockingManager x:Name="dockingManager" Grid.Row="2" Grid.Column="0"  BorderThickness="0"
                    Margin="5 5 0 5" DocumentsSource="{Binding ConfigViews}" >
      <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
        <local:LayoutStyleSelector>
          <local:LayoutStyleSelector.ConfigViewStyle>
            <Style TargetType="{x:Type avalonDock:LayoutItem}">
              <Setter Property="Title" Value="{Binding Model.TitleAlias}" />
              <Setter Property="CanClose" Value="False" />
              <Setter Property="ToolTip" Value="{Binding Model.ConfigFileName}"/>
              <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
              <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
              <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
            </Style>
          </local:LayoutStyleSelector.ConfigViewStyle>
          <local:LayoutStyleSelector.ToolStyle>
            <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
              <Setter Property="Width" Value="200" />
            </Style>
          </local:LayoutStyleSelector.ToolStyle>
        </local:LayoutStyleSelector>
      </avalonDock:DockingManager.LayoutItemContainerStyleSelector>
      <avalonDock:DockingManager.LayoutItemTemplateSelector>
        <local:LayoutTemplateSelector>
          <local:LayoutTemplateSelector.ConfigViewTemplate>
            <DataTemplate>
              <Grid Margin="10 0 0 0" >
                <Grid.Resources>
                  <Style TargetType="TextBox" BasedOn="{StaticResource baseTextboxStyle}">
                    <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
                    <Setter Property="Height" Value="22"></Setter>
                    <Setter Property="Margin" Value="5 0 5 0"></Setter>
                  </Style>
                </Grid.Resources>
                <Grid.RowDefinitions>
                  <RowDefinition Height="15"/>
                  <RowDefinition Height="*"/>
                  <RowDefinition Height="5"/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="1" Grid.Column="0"  Margin="0 0 10 0" IsEnabled="{Binding IsUIEnabled}" >
                  <Grid.RowDefinitions>
                    <RowDefinition Height="5"  Name="ConfigGridRow0"/>
                    <RowDefinition Height="28" Name="ConfigGridRow1"/>
                    <RowDefinition Height="45" Name="ConfigGridRow2"/>
                    <RowDefinition Height="28" Name="ConfigGridRow3"/>
                    <RowDefinition Height="28" Name="ConfigGridRow4"/>
                    <RowDefinition Height="30" Name="ConfigGridRow5"/>
                    <RowDefinition Height="*"  Name="ConfigGridRow6"/>
                    <RowDefinition Height="5"  Name="ConfigGridRow7"/>
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="115"/>
                    <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <Button Grid.Row="1" Grid.Column="0" Content="WorkDirectory:" Command="{Binding OpenFolderCommand}" CommandParameter="{Binding GeneratorConfig.WorkDir}" Style="{StaticResource linkButtonStyle}" />
                  <Grid Grid.Row="1" Grid.Column="1" >
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*" />
                      <ColumnDefinition Width="50" />
                    </Grid.ColumnDefinitions>
                    <TextBox Grid.Column="0" Name="txtWorkDir" Text="{Binding GeneratorConfig.WorkDir, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                    <Button Grid.Column="1" Content="..." Height="23" Margin="2 0 2 0" VerticalAlignment="Top" Command="{Binding SelectFolderCommand}"></Button>
                  </Grid>
                  <Button Grid.Row="2" Grid.Column="0" Content="ConnectionStr:" Name="btnConnStrHelp" Style="{StaticResource linkButtonStyle}" Command="{Binding OpenConnStrHelpCommand}"/>
                  <Grid Grid.Row="2" Grid.Column="1" >
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*" />
                      <ColumnDefinition Width="50" />
                    </Grid.ColumnDefinitions>
                    <TextBox Grid.Column="0" Height="40" Name="txtConnStr" Text="{Binding GeneratorConfig.ConnectionString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" />
                    <Button Grid.Column="1" Content="Test" Height="23" Margin="2 0 2 0" VerticalAlignment="Top" Command="{Binding TestConnectionCommand}"></Button>
                  </Grid>
                  <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2">
                    <Label   Content="Schema:" Name="lblSchema" Style="{StaticResource headerLabelStyle}" />
                    <TextBox Name="txtSchema" Width="150" Text="{Binding GeneratorConfig.TableSchema, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                    <Label   Margin="40 0 0 0" Content="CommSchema:" Name="lblCommSchema" Style="{StaticResource headerLabelStyle}" Width="100"/>
                    <TextBox Name="txtCommSchema" Width="150" Text="{Binding GeneratorConfig.CommentSchema, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  </StackPanel>
                  <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2">
                    <Label   Content="TableFilter:" Name="lblTableFilter" Style="{StaticResource headerLabelStyle}"/>
                    <TextBox Width="150"  Name="txtTableFilter" Text="{Binding GeneratorConfig.TableFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                    <Button  Margin="40 0 0 0"  Content="TableNames:" Name="btnTableNames" Style="{StaticResource linkButtonStyle}" Width="100" Command="{Binding ShowSchemaInfoCommand}"/>
                    <TextBox ToolTip="(comma seperated names)" Width="150" Text="{Binding GeneratorConfig.TableNames, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                  </StackPanel>
                  <Label  Grid.Row="5" Grid.Column="0" Content="Template:" Style="{StaticResource headerLabelStyle}" />
                  <Button Grid.Row="5" Grid.Column="1" Content="Add Template" Height="22"    
                          Width="100" Command="{Binding AddTemplateCommand}" Background="#FFA7CDF0" 
                          IsEnabled="{Binding IsUIEnabled}" HorizontalAlignment="Right"/>
                  <Grid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="220"/>
                      <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ListView Grid.Row="0" Grid.Column="0" Name="listTemplate"
                              BorderThickness="0"
                              ItemsSource="{Binding GeneratorConfig.Templates}" 
                              SelectionMode="Single" Focusable="True"
                              SelectedIndex="{Binding SelectedTemplateIndex}">
                      <ListView.ItemTemplate>
                        <DataTemplate>
                          <Grid>
                            <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="22" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Row="0" Grid.Column="0" Margin="5 0 0 0" Orientation="Horizontal" Height="50">
                              <CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" VerticalAlignment="Center" />
                              <TextBlock Text="{Binding Name}" VerticalAlignment="Center"></TextBlock>
                              <TextBlock Text="{Binding Tip}" VerticalAlignment="Center"/>
                            </StackPanel>
                            <Button Content="x" Grid.Column="1" BorderThickness="0" Height="20" Background="Transparent"
                                    Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=3}, Path=DataContext.DeleteItemCommand}" 
                                    CommandParameter="{Binding}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected, Converter={StaticResource visibleConverter}}" />
                            <Grid.Triggers>
                              <EventTrigger RoutedEvent="GotFocus">
                                <BeginStoryboard>
                                  <Storyboard>
                                    <BooleanAnimationUsingKeyFrames Duration="00:00:00" Storyboard.Target="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Storyboard.TargetProperty="IsSelected">
                                      <DiscreteBooleanKeyFrame Value="True" />
                                    </BooleanAnimationUsingKeyFrames>
                                  </Storyboard>
                                </BeginStoryboard>
                              </EventTrigger>
                            </Grid.Triggers>
                          </Grid>
                        </DataTemplate>
                      </ListView.ItemTemplate>
                    </ListView>
                    <GridSplitter Width="1" BorderBrush="Gray" BorderThickness="1" />
                    <ScrollViewer Grid.Row="0" Grid.Column="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                      <Grid Margin="5 0 0 0" Background="White" Grid.Row="0" Grid.Column="1" DataContext="{Binding ElementName=listTemplate,Path=SelectedItem}" IsEnabled="{Binding ., Converter={StaticResource bindingNotNullConverter}}" >
                        <StackPanel Margin="5 5">
                          <StackPanel Orientation="Horizontal">
                            <Label Content="Name:" Margin="0 5 0 0"/>
                            <CheckBox Content="Is Including" IsChecked="{Binding IsIncluding, Mode=TwoWay}" IsEnabled="{Binding Enabled}" 
                                      ToolTip="You can use '${include(templateFileName.txt)}' to include other templates.'" 
                                      Margin="105 5 0 0" HorizontalAlignment="Right" VerticalAlignment="Center" VerticalContentAlignment="Center"  />
                          </StackPanel>
                          <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                          <Button Margin="0 5 0 0" Content="TemplateFile:" Style="{StaticResource linkButtonStyle}" ToolTip="Edit Template"
                                  Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=DataContext.OpenFileCommand}" 
                                  CommandParameter="{Binding FileName}" Grid.Row="0" Grid.Column="1" IsEnabled="{Binding Enabled}" />
                          <TextBox Text="{Binding FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding Enabled}" />
                          <StackPanel Margin="0 5 0 0" Orientation="Horizontal">
                            <Button Margin="0 5 0 0" Content="OutputFile:" Style="{StaticResource linkButtonStyle}" ToolTip="Open output directory"
                                    Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=DataContext.OpenFolderCommand}" 
                                    CommandParameter="{Binding OutputFileName}" Grid.Row="1" Grid.Column="1" >
                              <Button.IsEnabled>
                                <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                  <Binding Path="Enabled" />
                                  <Binding Path="IsIncluding" />
                                </MultiBinding>
                              </Button.IsEnabled>
                            </Button>
                            <CheckBox Margin="77 5 0 0" VerticalAlignment="Center" VerticalContentAlignment="Center"  Content="Clear Output Directory"  IsChecked="{Binding ClearOutputDir, Mode=TwoWay}">
                              <CheckBox.IsEnabled>
                                <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                  <Binding Path="Enabled" />
                                  <Binding Path="IsIncluding" />
                                </MultiBinding>
                              </CheckBox.IsEnabled>
                            </CheckBox>
                            <CheckBox Margin="35 5 0 0" VerticalAlignment="Center" VerticalContentAlignment="Center"  Content="Append Output"  IsChecked="{Binding Append, Mode=TwoWay}" >
                              <CheckBox.IsEnabled>
                                <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                  <Binding Path="Enabled" />
                                  <Binding Path="IsIncluding" />
                                </MultiBinding>
                              </CheckBox.IsEnabled>
                            </CheckBox>
                          </StackPanel>
                          <TextBox Text="{Binding OutputFileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}">
                            <TextBox.IsEnabled>
                              <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                <Binding Path="Enabled" />
                                <Binding Path="IsIncluding" />
                              </MultiBinding>
                            </TextBox.IsEnabled>
                          </TextBox>
                          <Label  Content="Encoding:" Margin="0 10 0 0"/>
                          <ComboBox Margin="5 0 0 0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}, AncestorLevel=1}, Path=DataContext.EncodingNames}"
                                    SelectedItem="{Binding Encoding, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                    IsEditable="True" HorizontalAlignment="Left" Style="{StaticResource comboBoxStyle}">
                            <ComboBox.IsEnabled>
                              <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                <Binding Path="Enabled" />
                                <Binding Path="IsIncluding" />
                              </MultiBinding>
                            </ComboBox.IsEnabled>
                          </ComboBox>
                          <Button Content="{Binding TipSQL}" Margin="5 15 0 0" Foreground="Blue"
                                  Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=DataContext.OpenSQLEidtorCommand}" 
                                  CommandParameter="{Binding}" Width="100" Height="22" HorizontalAlignment="Left">
                            <Button.IsEnabled>
                              <MultiBinding Converter="{StaticResource multiEnabledConverter}">
                                <Binding Path="Enabled" />
                                <Binding Path="IsIncluding" />
                              </MultiBinding>
                            </Button.IsEnabled>
                          </Button>
                        </StackPanel>
                      </Grid>
                    </ScrollViewer>
                  </Grid>
                </Grid >
              </Grid>
            </DataTemplate>
          </local:LayoutTemplateSelector.ConfigViewTemplate>
        </local:LayoutTemplateSelector>
      </avalonDock:DockingManager.LayoutItemTemplateSelector>
      <avalonDock:LayoutRoot>
        <avalonDock:LayoutPanel Orientation="Vertical">
          <avalonDock:LayoutDocumentPane />
        </avalonDock:LayoutPanel>
        <avalonDock:LayoutRoot.RightSide>
          <avalonDock:LayoutAnchorSide>
            <avalonDock:LayoutAnchorGroup>
              <avalonDock:LayoutAnchorable x:Name="dockLogView" Title="LogView" CanClose="False" CanHide="False" AutoHideWidth="200">
                <TextBox Text="{Binding LogViewModel.ExecutingLog}" TextWrapping="NoWrap" IsReadOnly="True" FontSize="10" 
                         HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" FontFamily="Consolas">
                  <i:Interaction.Triggers>
                    <i:EventTrigger EventName="TextChanged">
                      <gmc:EventToCommand PassEventArgsToCommand="True" Command="{Binding LogViewModel.LogChangedCommand}" />
                    </i:EventTrigger>
                  </i:Interaction.Triggers>
                </TextBox>
              </avalonDock:LayoutAnchorable>
              <avalonDock:LayoutAnchorable x:Name="globalParameters" Title="Global Parameters" CanClose="False" CanHide="False" AutoHideWidth="200">
                <Grid>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="50"></RowDefinition>
                  </Grid.RowDefinitions>
                  
                  <DataGrid x:Name="GlobalParameterDataGrid" Grid.Row="0" AutoGenerateColumns="True"  Margin="0 0 10 0"  ColumnWidth="94" CanUserAddRows="False"
                          Style="{StaticResource MetroDataGridStyle}" ItemsSource="{Binding GlobalParameters}" ></DataGrid>
                  <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
                    <Button Style="{DynamicResource MetroCircleButtonStyle}" Height="40" Width="40" VerticalAlignment="Top" Command="{Binding AddGlobalParamCommand}">
                      <Rectangle Width="20" Height="20">
                        <Rectangle.Fill>
                          <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_add}" />
                        </Rectangle.Fill>
                      </Rectangle>
                    </Button>
                    <Button Style="{DynamicResource MetroCircleButtonStyle}" Height="40" Width="40" VerticalAlignment="Top"
                             Command="{Binding RemoveGlobalParamCommand}" CommandParameter="{Binding ElementName=GlobalParameterDataGrid, Path=SelectedItem}">
                      <Rectangle Width="20" Height="20">
                        <Rectangle.Fill>
                          <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_delete}" />
                        </Rectangle.Fill>
                      </Rectangle>
                    </Button>
                  </StackPanel>
                 
                </Grid>
                
              </avalonDock:LayoutAnchorable>
            </avalonDock:LayoutAnchorGroup>
          </avalonDock:LayoutAnchorSide>
        </avalonDock:LayoutRoot.RightSide>
      </avalonDock:LayoutRoot>
    </avalonDock:DockingManager>
  </Grid>
</Controls:MetroWindow>